<template>
  <div class="ximd-map-footer-warpper">
    <div v-for="(item, key) in dataList" @click="setActive(item)" @dblclick="setPageName(item)">
      <div :class="`xmind-name ${activeId === item.id ? 'active' : ''}`" v-if="!item.editFlag">
        <span>{{ item.name }}</span>
        <el-icon><ArrowDown /></el-icon>
      </div>
      <el-input v-else v-model="item.name" size="small" @keyup.enter="resetPageName(item)" style="width: 100px"></el-input>
    </div>
    <div class="add-btn" title="新增画布" @click="addCanvas">
      <el-icon><Plus /></el-icon>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import type { IMindData } from '../../types';
import { nanoid } from 'nanoid';
defineOptions({
  name: 'MindMapFooter',
});
// const props = defineProps({
//   data: Object as PropType<IMindData[]>,
// });

// const dataList = ref(props.data);
const state = ref<string>('1');
const activeId = ref<string>('1');
const dataList = ref<IMindData[]>([
  { id: '1', name: '画布1', editFlag: false },
  { id: '2', name: '画布1', editFlag: false },
]);
const setPageName = (item: IMindData) => {
  dataList.value.forEach((info) => {
    info.editFlag = false;
  });
  item.editFlag = true;
};
const resetPageName = (item: IMindData) => {
  item.editFlag = false;
};
const addCanvas = () => {
  dataList.value.push({
    id: nanoid(),
    name: '新画布',
    editFlag: false,
  });
};
const setActive = (item: IMindData) => {
  activeId.value = item.id;
};
const setState = () => {
  state.value = state.value === '1' ? '2' : '1';
};
</script>
<style lang="scss" scoped>
.ximd-map-footer-warpper {
  display: flex;
  justify-content: start;
  align-items: center;
  width: 100%;
  height: 30px;
  padding: 0 10px;
  background-color: #f1f3f4;
  border-top: 1px solid #dadce0;
  border-bottom: 1px solid #dadce0;

  .xmind-name {
    display: flex;
    align-items: center;
    height: 22px;
    line-height: 22px;
    font-size: 12px;
    padding: 0 10px;
    border-radius: 5px;
    align-items: center;
    cursor: pointer;
    .span {
      padding-right: 5px;
    }
  }
  .active {
    background-color: #a8abb2;
  }
  .add-btn {
    height: 22px;
    line-height: 22px;
    margin: 0 5px;
    padding: 0 3px;
  }
  .add-btn:hover {
    background-color: #a8abb2;
    border-radius: 5px;
    cursor: pointer;
  }
}
</style>
